/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.crawl.util;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author drafkind
 */
public class Lists {
  public static <T> void forEach(Iterable<T> i, VoidLambda<T> v) {
    for (T t : i)
      v.invoke(t);
  }

  public static <T> List<T> collect(Iterable<T> i, BooleanLambda<T> b) {
    List<T> c = new ArrayList<T>();
    for (T t: i)
      if (b.invoke(t))
        c.add(t);

    return c;
  }

  public static <T,U> List<U> map(Iterable<T> i, Lambda<T,U> ell) {
    List<U> c = new ArrayList<U>();
    for (T t: i)
      c.add(ell.invoke(t));

    return c;
  }

  public static interface VoidLambda<T> {
    void invoke(T t);
  }

  public static interface BooleanLambda<T> {
    boolean invoke(T t);
  }

  public static interface Lambda<T,U> {
    U invoke(T t);
  }
}
